package com.csh.oss.controller;

import com.csh.oss.service.FileService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;

/**
 * 文件操作controller
 */
@RestController
@RefreshScope
@RequestMapping("/minio")
public class FileController {

    @Resource
    private FileService fileService;

    @Value("${storage.service.type}")
    private String storageType;

    @RequestMapping("/testGetAllBuckets")
    public String testGetAllBuckets(){
        List<String> allBucket = fileService.getAllBucket();
        return allBucket.get(0);
    }

    @RequestMapping("/testNacos")
    public String testNacos(){
        return storageType;
    }

    /**
     * 上传文件，所有的上传都走这个接口
     */
    @RequestMapping("/upload")
    public String upload(MultipartFile uploadFile, String bucket, String objectName){
        return fileService.uploadFile(uploadFile,bucket,objectName);
    }
}
